﻿// -----------------------------------------------------------------------
// <copyright file="BadMessageException.cs" company="Zen Design Corp">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Pap.Parser
{
	using System;
	using System.Runtime.Serialization;

	/// <summary>
	/// If the PAP message was rejected by the PPG, this exception will be 
	/// thrown with the details from the PAP badmessage-response message.
	/// </summary>
	public class BadMessageException : Exception
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="BadMessageException"/> class.
		/// </summary>
		public BadMessageException()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="BadMessageException"/> class.
		/// </summary>
		/// <param name="response">The response.</param>
		public BadMessageException(BadMessageResponse response)
		{
			Response = response;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="BadMessageException"/> class.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
		/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
		/// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
		public BadMessageException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			Response = (BadMessageResponse)info.GetValue("Response", typeof(BadMessageResponse));
		}

		/// <summary>
		/// Gets or sets the response.
		/// </summary>
		/// <value>The response.</value>
		public BadMessageResponse Response
		{
			get;
			private set;
		}

		/// <summary>
		/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
		/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic). </exception>
		/// <PermissionSet>
		/// 	<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
		/// 	<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
		/// </PermissionSet>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			if (Response != null)
			{
				info.AddValue("Response", Response);
			}
		}
	}
}
